<template>
	<view class="home">
		<view class="loop">
			<up-swiper height="463" :list="list5" @change="e => current = e.current" @click="clickloop"
				:autoplay="false">
				<template #indicator>
					<view class="indicator">
						<view class="indicator__dot" v-for="(item, index) in list5" :key="index"
							:class="[index === current && 'indicator__dot--active']">
						</view>
					</view>
				</template>
			</up-swiper>
		</view>
		<!-- <view class="homeback"></view> -->
		<view class="headertop" :style="{'background':flag1?'#FCE5CC':''}">
			<view class="box"
				:style="{'margin-top':statusBarHeight+'px','width':'100%','height':barHeight+'px','display':'flex','align-items': 'center'}">
				<image src="https://39gongli.oss-cn-beijing.aliyuncs.comhttp://shop.hacuu.com/static/Group 2@2x.png"
					class="pagelefticon" mode=""></image>
			</view>
		</view>
		<view class="centertop">
			<view class="seacherbox">
				<image src="http://shop.hacuu.com/static/Frame@2x(1).png" class="seacherbox_icon" mode=""></image>
				<input type="text" placeholder="请输入关键词进行搜索" />
				<view class="sechbvtn">
					搜索
				</view>
			</view>
			<view class="tuijiansousuo">
				<view class="sousuo" v-for="item in sousuoci" :key="item.id">
					{{item.keywords}}
				</view>
			</view>
		</view>

		<view style="width: 100%;margin-top: 530rpx;overflow: hidden;background: #F7F8FA;" v-if="homecontent.vip">
			<view class="memberbox" @click="gopage('会员卡')">
				<image src="http://shop.hacuu.com/static/Group 11585@2x.png" class="memberbox_backimg" mode="widthFix">
				</image>
				<image src="http://shop.hacuu.com/static/微信图片_20250523140933.png" class="qyicon" mode=""></image>
				<view class="membertext">
					会员专享价 & 好物低至{{homecontent.vip.zhekou}}折起
				</view>
				<image src="http://shop.hacuu.com/static/微信图片_20250523140920.png" class="membergeren" mode=""></image>
				<view class="hybox">
					<image src="http://shop.hacuu.com/static/Rectangle 24326@2x.png" class="hyboxback" mode=""></image>
					<image src="http://shop.hacuu.com/static/Frame@2x(2).png" class="membericon" mode=""></image>
					<view class="t">
						专属特权等您开启
					</view>
				</view>
				<view class="btn">
					加入会员 ￥{{homecontent.vip.price}}/起
				</view>
			</view>
			<image :src="homecontent.zhinan" class="ggy" @click="gopage('购买指南')" mode=""></image>
		</view>



		<view class="bottomclassify">
			<view class="topclssify">
				<view :class="-1==actice?'item1':'item'" @click="qiehuan(-1)">
					<view class="title">
						全部分类
					</view>
					<image src="http://shop.hacuu.com/static/Ellipse 2642@2x.png" class="imgbotom1" mode=""
						v-if="-1==actice"></image>
					<image class="imgbotom" v-if="-1!=actice">

					</image>
					<view class="borderline">

					</view>
				</view>
				<view :class="index==actice?'item1':'item'" @click="qiehuan(index)" v-for="(item,index) in classlistarr"
					:key="item.id">
					<view class="title">
						{{item.name}}
					</view>
					<image :src="item.image" class="imgbotom" mode="" v-if="index!=actice"></image>
					<image src="http://shop.hacuu.com/static/Ellipse 2642@2x.png" class="imgbotom1" mode=""
						v-if="index==actice"></image>
					<view class="borderline">

					</view>
				</view>
			</view>
			<view class="shangplist">
				<view class="itemsp" v-for="item in List" :key="item.id" @click="gopage('商品详情',item.id)">
					<image :src="item.image" class="spt" mode=""></image>
					<view class="texts">
						<view class="t1">
							{{item.title}}
						</view>
						<view class="t2">
							{{item.subtitle}}
						</view>
					</view>
					<view class="jiageline">
						<view class="jiage">
							￥{{jigaefun(item.price[0])}}. <span
								style="font-size:20rpx ;">{{jigaefun(item.price[0],'后')}}</span>
						</view>
						<image src="http://shop.hacuu.com/static/Frame@2x(3).png" class="caricon" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<userlogin ref="denglu"></userlogin>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted,
		reactive,

	} from 'vue'
	import {
		onLoad,
		onPageScroll
	} from "@dcloudio/uni-app";
	import userlogin from '@/components/getuser/getuser.vue'
	import {
		bannerlist,
		indexfile,
		searchkey,
		classlist,
		goods
	} from '@/api/home.js'
	const flag1 = ref(false)
	const barHeight = ref('')
	const query = reactive({
		page: 1,
		limit: 10,
		keyword: '',
		category_id: ''
	})
	const statusBarHeight = ref('')
	const classlistarr = ref([])
	const actice = ref(-1)
	const show = ref(true)
	const List = ref([])
	const total = ref(0)
	const current = ref(0)
	const denglu = ref(null)
	const sousuoci = ref([])
	const homecontent = ref({})
	const list5 = ref([
		'http://shop.hacuu.com/static/Group 11582@2x.png',
		'http://shop.hacuu.com/static/Group 11582@2x.png',
		'http://shop.hacuu.com/static/Group 11582@2x.png',
	]);
	onLoad(() => {
		init()
		shangpinginit()
	})
	onPageScroll((e) => {
		console.log(total.value, List.value.length);
		if (total.value > List.value.length) {
			query.page++
			shangpingListrinit()
		}
	})
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})

	function qiehuan(num) {
		actice.value = num
		query.page = 1
		List.value = []
		if (num == -1) {
			query.category_id = ''
		} else {
			query.category_id = classlistarr.value[num]['id']
		}
		shangpingListrinit()
	}

	function jigaefun(str1, strr) {
		let number = str1
		let str = number.toString(); // 转换为字符串 "100.00"
		let parts = str.split('.'); // 按小数点分割
		let integerPart = parts[0]; // "100"
		let decimalPart = parts[1] || "00"; // "00"（如果没有小数部分，默认 "00"）
		if (!strr) {
			return integerPart
		} else {
			return decimalPart
		}

	}
	async function init() {
		const res = await bannerlist()
		if (res.code == 1) {
			list5.value = res.data.map(item => item.image)
		}
		// 首页新手指南，vip
		const res1 = await indexfile()
		if (res1.code == 1) {
			homecontent.value = res1.data
		}
		// 搜索词
		const res2 = await searchkey()
		if (res2.code == 1) {
			sousuoci.value = res2.data
		}

	}
	// 商品分类
	async function shangpinginit() {
		const res = await classlist({
			pid: 0
		})
		if (res.code == 1) {
			classlistarr.value = res.data
			shangpingListrinit()
		}
	}
	async function shangpingListrinit() {
		const res = await goods(query)
		if (res.code == 1) {
			console.log(res, 'res----------------');
			List.value.push(...res.data.data)
			total.value = res.data.total
		}
	}


	function gopage(str, id) {
		if (str == '会员卡') {
			if (!uni.getStorageSync('token')) {
				denglu.value.DengLu()
				return
			}
			uni.navigateTo({
				url: '/pages/my/memberCard'
			})
		} else if (str == '购买指南') {
			uni.navigateTo({
				url: ''
			})
		} else if (str == '商品详情') {
			uni.navigateTo({
				url: '/pages/home/shangpdetail?id=' + id
			})
		}
	}
</script>

<style lang="scss">
	.ggy {
		width: 686rpx;
		height: 272rpx;
		margin: 32rpx auto;
		display: block;
	}

	.bottomclassify {
		width: 100%;
		overflow: hidden;
		background: #fff;

		.shangplist {
			width: 686rpx;
			margin: auto;
			margin-top: 24rpx;
			overflow: hidden;
			display: flex;
			flex-wrap: wrap;

			.itemsp {
				width: 334rpx;
				background: #F7F8FA;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				overflow: hidden;
				margin-bottom: 24rpx;

				.spt {
					width: 318rpx;
					height: 318rpx;
					margin: auto;
					margin-top: 8rpx;
					display: block;
				}

				.jiageline {
					width: 302rpx;
					margin-top: 24rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 22rpx;
					margin: 22rpx auto;

					.caricon {
						width: 36rpx;
						height: 36rpx;
					}

					.jiage {
						font-weight: bold;
						font-size: 28rpx;
						color: #F53F3F;
					}
				}

				.texts {
					width: 302rpx;
					overflow: hidden;
					margin: auto;

					.t1 {
						white-space: nowrap;
						/* 防止文本换行 */
						overflow: hidden;
						/* 隐藏溢出的内容 */
						text-overflow: ellipsis;
						/* 显示省略号 */
						width: 100%;
						margin-top: 18rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #1D2129;
					}

					.t2 {
						white-space: nowrap;
						/* 防止文本换行 */
						overflow: hidden;
						/* 隐藏溢出的内容 */
						text-overflow: ellipsis;
						/* 显示省略号 */
						width: 100%;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 22rpx;
						color: #4E5969;
						margin-top: 14rpx;
					}
				}
			}
		}

		.topclssify {
			width: 100%;
			height: 94rpx;
			white-space: nowrap;
			overflow: hidden;
			overflow-x: scroll;

			// background: #F7F8FA;
			.item1 {
				padding: 0 32rpx;
				display: inline-block;
				border-radius: 0 30rpx 0 0;
				border-radius: 0 30rpx;

				.title {
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 30rpx;
					color: #1D2129;
					width: 100%;
					text-align: center;
					margin-top: 18rpx;
					border-radius: 30rpx;
				}

				.imgbotom1 {
					width: 36rpx;
					height: 10rpx;
					margin: auto;
					display: block;
					margin-bottom: 30rpx;
				}

				.imgbotom {
					width: 80rpx;
					height: 54rpx;
					margin: auto;
					display: block;
				}
			}

			.item {
				padding: 0 32rpx;
				display: inline-block;
				background: #F7F8FA;
				border-radius: 0 0 0 30rpx;
				position: relative;

				.borderline {
					width: 2rpx;
					height: 64rpx;
					background: #E5E6EB;
					right: 0rpx;
					top: 18rpx;
					position: absolute;
				}

				.title {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #1D2129;
					width: 100%;
					text-align: center;
					margin-top: 18rpx;
				}

				.imgbotom1 {
					width: 36rpx;
					height: 10rpx;
					margin: auto;
					display: block;
					margin-bottom: 30rpx;
				}

				.imgbotom {
					width: 80rpx;
					height: 54rpx;
					margin: auto;
					display: block;
				}
			}
		}
	}

	.memberbox {
		width: 718rpx;
		height: 432rpx;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		margin: auto;
		z-index: 999;
		position: relative;
		overflow: hidden;

		&_backimg {
			width: 100%;
			height: 432rpx;
			position: absolute;
			z-index: -1;
		}

		.qyicon {
			width: 104rpx;
			height: 26rpx;
			position: absolute;
			top: 35rpx;
			right: 36rpx;

		}

		.membertext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #240A00;
			margin-left: 42rpx;
			margin-top: 50rpx;
		}

		.membergeren {
			width: 236rpx;
			height: 48rpx;
			margin-top: 28rpx;
			margin-left: 42rpx;
		}

		.btn {
			width: 638rpx;
			height: 84rpx;
			background: linear-gradient(#CD936A 0%, #F5C89D 100%);
			border-radius: 200rpx 200rpx 200rpx 200rpx;
			margin: auto;
			margin-top: 90rpx;
			text-align: center;
			line-height: 84rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 32rpx;
			color: #FFFFFF;
		}

		.hybox {
			width: 236rpx;
			height: 36rpx;
			margin-top: 26rpx;
			position: relative;
			display: flex;
			align-items: center;
			margin-left: 42rpx;

			.hyboxback {
				width: 236rpx;
				height: 36rpx;
				position: absolute;
				z-index: -1;
			}

			.membericon {
				width: 28rpx;
				height: 28rpx;
				margin-left: 20rpx;
			}

			.t {
				font-weight: 400;
				font-size: 20rpx;
				color: #795533;
				margin-left: 8rpx;
			}
		}
	}

	.loop {
		width: 100%;
		border-radius: 0rpx 0rpx 64rpx 64rpx;
		overflow: hidden;
		position: absolute;
		z-index: -1;

		::v-deep .u-swiper {
			// background: #F7F8FA;
			background-color: #F7F8FA !important;
		}
	}

	::v-deep .u-swiper__indicator {
		bottom: 35px !important;
	}

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			width: 30rpx;
			height: 4rpx;
			border-radius: 2rpx 2rpx 2rpx 2rpx;
			background: rgba(166, 109, 51, 0.2);
			margin: 0 2px;
			transition: background-color 0.3s;

			&--active {
				background-color: #A4692D;
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	.centertop {
		width: 100%;
		margin-top: 182rpx;
		overflow: hidden;

		.tuijiansousuo {
			width: 718rpx;
			margin-left: 32rpx;
			overflow-x: scroll;
			white-space: nowrap;
			margin-top: 20rpx;
			z-index: 99999;

			.sousuo {
				display: inline-block;
				background: rgba(255, 255, 255, 0.34);
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				height: 46rpx;
				padding: 0 14rpx;
				line-height: 46rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: #4E5969;
				margin-right: 20rpx;
			}
		}

		.seacherbox {
			width: 686rpx;
			height: 68rpx;
			margin: auto;
			background: #FFFFFF;
			border-radius: 34rpx 34rpx 34rpx 34rpx;
			display: flex;
			align-items: center;
			position: relative;

			&_icon {
				width: 32rpx;
				height: 32rpx;
				margin-left: 20rpx;
			}

			.sechbvtn {
				width: 112rpx;
				position: absolute;
				right: 0%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #A46F3A;
				height: 44rpx;
				border-left: 2rpx solid #E5E6EB;
			}
		}
	}

	@import '@/css/home.scss'
</style>